import fetch from "./fetch";

// 判断环境。使用不同的api
// development 开发过程中的环境(测试)
// production 生产环境

// 在编译的时候执行

// 请求首页的接口
interface UserObject {
  name: string;
  sex: number;
  birthday: any;
  captcha?: number | string;
  mobile: string | number;
  plate_number?: string;
  openid?: string;
}
// 会员更新
interface memberUpdate {
  openid: string;
  mobile?: string;
  name: string;
  sex: number;
  birthday: null | string | Date;
  session_member_id?: number;
}

// 响应
// 统一类型
interface ResData<T> {
  code: number;
  msg: string;
  data: T;
}
// 验证码
interface CaptchaData {
  mobile?: string;
  captcha: string;
  code?:string;
}
// 注册
interface RegisterData {
  // status: number;
  openid: string;
  mobile: string;
  name: string;
  sex: number;
  birthday?: string;
  updated_at?: string;
  created_at?: string;
  id?: number;
  captcha: string;
}
// 会员更新/api/member/update
// data: any[];

// 会员详情/api/member/info?member_id
interface infoData {
  id: number;
  status: number;
  openid: string;
  mobile: string;
  code: string;
  name: string;
  sex: number;
  birthday: string;
  memo?: any;
  created_at: string;
  updated_at: string;
  session_member_id: number;
  member_car_plate_number:string
}

// 检查并登录
interface ApiCheckLoginData {
  member_id: number;
}
// 会员详情
interface Datum {
  id: number;
  member_id: number;
  status: number;
  code: string;
  plate_number: string;
  sort: number;
  created_at: string;
  updated_at: string;
}

export const ApiGetHomeData = () =>
  fetch(
    `/6666?actionCode=1334411120332562440`,
    {},
    { "x-auth-token": "233215872556653923a7d74754313ca0" },
    "GET"
  );
// /1314/{actionCode}/{testType} 进入练习页面(题目分类列表)
// actionCode testType 1314/1334432040677867547/all
export const ApiActionCode = () =>
  fetch(
    `/1314/${"1334432040677867547"}/${"all"}`,
    {},
    { "x-auth-token": "233215872556653923a7d74754313ca0" },
    "GET"
  );

  // 验证码
  export const ApiSendCaptcha = (
    mobile: number | string
  ): Promise<ResData<CaptchaData>> =>
    fetch(`/base/sendCaptcha`, { mobile }, {}, "POST");

// 注册
  // export const ApiRegister = (params: UserObject): Promise<ResData<RegisterData>> =>{
  //   // console.log(params, "params");
  //   // console.log({ ...params }, "{ ...params }");
  //  return fetch(`/member/register`, { ...params }, {}, "POST");
  // }
  export const ApiRegister = (
    params: UserObject
  ): Promise<ResData<RegisterData>> => {
    // console.log(params, "params");
    // console.log({ ...params }, "{ ...params }");
    return fetch(`/member/registerWithCar`, { ...params }, {}, "POST");
  };

// 检查并登录
export const ApiCheckLogin = (openid: string): Promise<ResData<ApiCheckLoginData>> =>
  fetch(`/member/checkLogin`, { openid }, {}, "POST");
  // 检查并登录
export const ApiLogout = (): Promise<ResData<any[]>> =>
  fetch(`/member/logout`, { }, {}, "POST");

// 会员更新/api/member/update
// data: any[];
export const ApiMemberUpdate = (params: memberUpdate): Promise<ResData<any[]>> => {
  // console.log({ ...params }, "{ ...params }");
  return fetch(`/member/update`, { ...params }, {}, "POST");
};
// 会员详情/api/member/info
export const ApiMemberInfo = (member_id: number): Promise<ResData<infoData>> => {
  return fetch(`/member/info`, { member_id }, {}, "POST");
};

// 会员车辆新增 /api/member-car/add
export const ApiMemberCarAdd = (plate_number: string): Promise<ResData<any[]>> => {
  return fetch(`member-car/add`, { plate_number }, {}, "POST");
};

// 会员车辆详情 /api/member-car/list
export const ApiMemberCarList = (): Promise<ResData<Datum[]>> => {
  return fetch(`/member-car/list`, {}, {}, "POST");
};


// 会员车辆更新 /api/member-car/update
export const ApiMemberCarUpdate = (params: {
  member_car_id: number;
  plate_number:string
}): Promise<ResData<any[]>> => {
  return fetch(`/member-car/update`, { ...params }, {}, "POST");
};

// 会员车辆更新状态 /api/member-car/updateStatus
export const ApiMemberCarUpdateStatus = (params: {
  member_car_id: number;
  status: number;
}): Promise<ResData<any[]>> => {
  // console.log(params, "params");
  return fetch(`/member-car/updateStatus`, { ...params }, {}, "POST");
};

// 会员车辆删除 /api/member-car/delete
export const ApiMemberCarDelete = (member_car_id: number): Promise<ResData<any[]>> => {
  return fetch(`/member-car/delete`, { member_car_id }, {}, "POST");
};
